﻿
//提示对话框
//id：弹窗的查询窗口  formname：查询的表单名称
$.SearchDialog = function (colid, formname)
{
    var txt = $("#" + colid).html();
    var id = newGuid();
    var isOK = false;
    return artDialog({
        title: '查询条件',
        id: id,
        fixed: true,
        lock: true,
        content: document.getElementById(colid),
        ok: function ()
        {
            isOK = true;
        },
        okVal: "查询", cancelVal: "取消", cancel: function ()
        {
            closeOver = null;
        }, closeOver: function ()
        {
            if (isOK)
            {
                AjaxToPage(formname, 1);
            }
        }
    });
};


//提示对话框
//content：显示内容  callback：完成回调
$.alert = function (content, callback)
{
    var id = newGuid();
    return art.dialog({
        title: '警告',
        id: id,
        icon: "warning",
        fixed: true,
        lock: true,
        content: "<span style='line-height:22px;'>" + _SetDialogContent(content, id) + "</span>",
        ok: true,
        close: callback
    });
};

//确认提示
//content：显示内容  yesCallback：选择是调用 noCallback：选择否调用
$.confim = function (content, yesCallback, noCallback)
{
    var id = newGuid();
    return art.dialog({
        title: '确认',
        id: id,
        icon: "question",
        fixed: true,
        lock: true,
        content: "<span style='line-height:22px;'>" + _SetDialogContent(content, id) + "</span>",
        resize: false,
        ok: yesCallback == null ? true : yesCallback,
        cancel: noCallback == null ? true : noCallback
    });
};

//短暂显示
// content：显示内容  follow：跟随控件 time：显示时间
$.tips = function (content, follow, time, funCall) {

    if (funCall == null) {
        funCall = function () { };
    }

    var id = newGuid();
    return art.dialog({
        id: id,
        title: false,
        cancel: false,
        fixed: true,
        lock: false,
        height: '20px',
        follow: document.getElementById(follow),
        close: funCall
    })
    .content('<div style="padding: 0 1em;">' + _SetDialogContent(content, id) + '</div>')
    .time(time || 1.5);
};

//短暂显示
// content：显示内容  follow：跟随控件 time：显示时间
$.tipsError = function (content, follow)
{
    // var idGuid="tipsError_"+newGuid();
    var id = "error_" + follow;
    var dg = artDialog({
        id: id,
        title: false,
        cancel: false,
        lock: false,
        padding: '0px 0px',
        follow: document.getElementById(follow)
    })
    .content("<div  style='padding:0 0px;color:#ffffff;width:100%;min-width:130px' class='aui_innerError'> " + _SetDialogContent("&nbsp;&nbsp;" + content, id) + "</div>");

    // alert($("#"+idGuid).parents(".aui_inner").html())

    //$("#"+idGuid).parents(".aui_inner").removeClass("aui_inner").addClass("aui_innerError");

    return dg;

};

//双值框 link 可以是控件ID或者链接地址，控件ID时必须#开头
// keyId key写入的控件ID 必须#开头
//valId val写入的控件ID 必须#开头
//callfun 完成的回调方法
$.DoubleDialog = function (link, keyId, valId, callfun) {

    var content = ""

    if (link.toString().indexOf('#') == 0) {
        content = $(link).html();
    } else {
        $.AjaxServer(link, null, function (data) { content = data; }, false);
    }

    var id = newGuid();
    return artDialog({
        id: id,
        title: "请选择",
        cancel: false,
        lock: false,
        padding: '0px 0px',
        content: _SetDialogContent(content, id),
        close: true,
        SetDouble: function (key, val, obj) {
     
            $(keyId).val(key);
            $(valId).val(val);

            if (callfun != null) {
                callfun(key, val, obj);
            }

            getCurrentDialog(obj).close();
        }
    })

};

//写入双值框
$.SetDoubleDialog = function (key, val, col)
{
    getCurrentDialog(col).SetDouble(key, val, col);
};



//生成对话框ID
function newGuid()
{
    var guid = "";
    for (var i = 1; i <= 32; i++)
    {
        var n = Math.floor(Math.random() * 16.0).toString(16);
        guid += n;
        if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
            guid += "-";
    }
    return guid;
}

//当前对话框
function getCurrentDialog(elm)
{
    ///<summary>
    /// 从点击对象中向上查找其所在的弹出层对象
    ///</summary>
    ///<param name="elm">当前在层中的操作对象,一般使用this即可</param>

    //从点击对象中向上查找所有:_artDialogId属性

    var values = $(elm).parents("[_dialogId]");

    var _dialogId = values.attr("_dialogId");
    var dialog = art.dialog.list[_dialogId];


    // var id= "error_"+follow;


    return dialog;
}


function _SetDialogContent(content, id)
{
    return "<div _dialogId='" + id + "'  >" + content + "</div>";
}

//清理所有错误提示对话框
function CloseAllError()
{
    $.each(art.dialog.list, function (id, value)
    {

        if (id.indexOf("error_") != -1)
        {
            value.close();
        }
    });

    return true;
}